package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Refund;
import cn.wolfcode.crm.query.RefundQueryForObject;
import cn.wolfcode.crm.service.IRefundService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 退款管理
 */
@Controller
@RequestMapping("refund")
public class RefundController {
    @Autowired
    private IRefundService refundService;

    @PermissionName("退款管理首页")
    @RequiresPermissions("refund:index")
    @RequestMapping("index")
    public String index(){
        return "refund/list";
    }

    @PermissionName("退款管理列表")
    @RequiresPermissions("refund:list")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(RefundQueryForObject qo){
        return refundService.query(qo);
    }

    @PermissionName("退款管理编辑")
    @RequiresPermissions("refund:edit")
    @RequestMapping("edit")
    @ResponseBody
    public JsonResult edit(Refund record){
        try{
            refundService.updateByPrimaryKey(record);
        }catch (Exception e){
            e.printStackTrace();
            new JsonResult("操作失败");
        }
        return new JsonResult();
    }

    @PermissionName("退款单新增")
    @RequiresPermissions("refund:save")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Refund record){
        try{
            refundService.insert(record);
        }catch (Exception e){
            e.printStackTrace();
            new JsonResult("操作失败");
        }
        return new JsonResult();
    }

    /**
     * 修改状态
     * @param feeId
     * @param stuId
     * @return
     */
    @PermissionName("退款记录审核")
    @RequiresPermissions("refund:changeState")
    @RequestMapping("changeState")
    @ResponseBody
    public JsonResult changeState(Long feeId, Long stuId){
        try{
            refundService.changeState(feeId,stuId);
        }catch (Exception e){
            e.printStackTrace();
            new JsonResult("审核失败");
        }
        return new JsonResult();
    }

}
